import java.util.Arrays;

/*
377
 */
public class CombinationSum4 {
    public static void main(String[] args) {
        CombinationSum4 combinationSum4 = new CombinationSum4();
        int[] test1 = new int[]{1,2,3};
        int[] test2 = new int[]{9};
        System.out.println(combinationSum4.combinationSum4(test1, 4));
        System.out.println(combinationSum4.combinationSum4(test2, 0));
    }
    public int combinationSum4(int[] nums, int target) {
        int[] dp = new int[target + 1];
        dp[0] =1 ;
        for (int i = 1; i <=target; i++) {
            for (int num : nums) {
                if(num<=i){
                    System.out.println(i+"-"+num+"="+(i-num));
                    System.out.println("before"+Arrays.toString(dp));
                    dp[i] += dp[i-num];
                    System.out.println("after"+Arrays.toString(dp));
                }
            }
        }
        return dp[target];
    }
}
